import java.util.ArrayList;

import processing.core.*;


public class CircleDynamicButton extends View {

	private PImage icon;
	private boolean selected;
	private String message;
	private int messageposX;
	private int messageposY;
	private int view;
	private boolean showMessage;
	CircleDynamicButton(float x_, float y_, float w_, float h_, MainView p, String img,  String message, int messagePosX, int messagePosY, int view,boolean showMessage) {
		super(x_, y_, w_, h_, p);
		this.icon = parent.loadImage(img); 
		
		this.selected = false;
		this.message = message;
		this.messageposX = messagePosX;
		this.messageposY = messagePosY;
		this.view = view;
		this.showMessage = showMessage;
		
		//icon.resize((int)w,(int)h);
				}
	
	void drawContent()
	  {
	
		parent.fill(255);
		if(!selected)
		parent.noStroke();
		else{
			parent.strokeWeight(6);
			parent.stroke(24,116,205);
		}
		parent.smooth();
		parent.ellipse(w/2, h/2, w, w);
		
		if(w == 400)
		parent.image(icon, w/2-icon.width/2, h/2-icon.height/2);//70, 70);
		else
			parent.image(icon, 0, 0);
			
		parent.noStroke();
		
		//parent.fill(0);
		//parent.rect(0,0 , w, h);
	  }
	 
	boolean contentPressed(float lx, float ly)
	  {
	   
		this.parent.view  = this.view;
		parent.changeView();
		
		 return true;
	  }
	boolean mouseDetected(float px, float py){
		 if (!ptInRect(px, py, x, y, w, h)){
			 selected = false;
			 return false;
			 
		 }
		 
		 float lx = px - x;
		 float ly = py - y;
		    // check our subviews first
		    for (int i = subviews.size()-1; i >= 0; i--) {
		      View v = (View)subviews.get(i);
		      if (v.mouseDetected(lx, ly)) return true;
		    }
		selected = true;
		parent.setElseFalse(this);
		if(showMessage)
		parent.setMainScreenMessage(this.message,  this.messageposX, this.messageposY);
		
		return true;
	}
	
	boolean isSelected(){
		return selected;
	}

	 void setSelected(boolean selected){
		 this.selected = selected;
	 }
	 
	 
}
